<?php 

session_start();

if (@$_REQUEST['actionType'] == "add")
{
	@$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]]["qty"] = @$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]]["qty"] + $_REQUEST["quantity"];
	header('Location:alcool.php?iid='.$_REQUEST["iid"].'&aid='.$_REQUEST["aid"]);
}
elseif (@$_REQUEST['actionType'] == "remove")
{
	@$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]]["qty"] = @$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]]["qty"] - $_REQUEST["quantity"];
	if (@$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]]["qty"] < 0)
	{
		@$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]]["qty"] = 0;
	}
	header('Location:alcool.php?iid='.$_REQUEST["iid"].'&aid='.$_REQUEST["aid"]);
}

@include 'include/header.php';

?>

<script type="text/javascript">
	function addBottle()
	{
		document.getElementById("actionType").value = 'add'
		form.submit();
	}
	
	function removeBottle()
	{
		document.getElementById("actionType").value = 'remove'
		form.submit();
	}
	
</script>
<?php 
$alcool = @$_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]];
?>
<form name="form" action="alcool.php" method="GET">

	<input type="hidden" name="iid" value="<?php echo $_REQUEST["iid"]; ?>">
	<input type="hidden" name="aid" value="<?php echo $_REQUEST["aid"]; ?>">
	<input type="hidden" id="actionType" name="actionType" value="">
	<div id="contenu">
		<div class="infos">
			<div class="photo">
				<?php echo " 
					<p><img src=\"images/".$alcool["image"]."\" alt=\"Photo\" /></p>"; 
				?>

			</div>
			<div class="infosGenerales">
				<h1>
					<?php echo $alcool["nom"]." (".$alcool["annee"].")"; 

					if ($alcool["rabais"])
					{
						echo "<img src=\"images/rabais.png\" width=\"16px\" height=\"16px\" alt=\"Rabais\" />";
					}

					if ($alcool["favoris"])
					{
						echo "<a href=\"favoris.php\" title=\"Favori\"><img src=\"images/favori.png\" alt=\"Favori\" title=\"Favori\" /> </a>";
					}
					echo "<a href=\"modifierAlcool.php?aid=". $_REQUEST["aid"]."&iid=".$_REQUEST["iid"]."\" title=\"Modifié\"><img src=\"images/edit.png\" width=\"16px\" height=\"16px\" alt=\"Modifié\" title=\"Modifié\" /> </a>";


					?>
				</h1>
				<h2>
					<?php echo $alcool["type"]." - ".$alcool["provenance"]; ?>
				</h2>
				<p>
					<?php echo $alcool["tauxAlcool"]; ?>
				</p>
				<p>
					<?php echo $alcool["cote"]; ?>
					/5
				</p>
				<p>
					<a href="inventaire.php?iid=<?php echo $_REQUEST["iid"]; ?>"><?php echo $alcool["qty"]; ?>
						bouteilles en inventaire</a> <a href="javascript:addBottle();"
						title="Ajouter"><img src="images/ajouter.png" alt="Ajouter" /> </a>
					<input name="quantity" type="text" maxlength="2" size="2" value="1"></input>
					<a href="javascript:removeBottle();" title="Enlever"><img
						src="images/enlever.png" alt="Enlever" /> </a>
				</p>
				<p>
				
				
				<div class="classification">
					<div class="cover"></div>
					<div class="progress" style="width: <?php $cote = $_SESSION["profils"][$_SESSION["profilActuel"]]["inventaires"][$_REQUEST["iid"]]["bouteilles"][$_REQUEST["aid"]]['cote'] / 5 * 100; echo $cote;?>%;"></div>
				</div>
				</p>
			</div>
		</div>
		<div class="description">
			<h2>Description</h2>
			<p>
				<?php echo str_replace("\n", "</p><p>", $alcool["description"]); ?>
			</p>
		</div>
		<div class="note">
			<h2>Note de dégustation</h2>
			<p>
				<?php echo str_replace("\n", "</p><p>", $alcool["notes"]); ?>
			</p>
		</div>
	</div>


</form>
</body>

</html>
